@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script type="text/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">论坛管理</a>
            <em>></em>
            <a href="#">添加讨论评论</a>
        </div>
        <!-- cur-position end -->

        <div class="gg-step">
            <form  id="advform">
{{--
                <input type="hidden" name="forum_discuss_id" id="forum_discuss_id" value="@if($forumDiscuss){{$forumDiscuss->id}}@endif"/>
--}}

                <input type="hidden" name="forum_id" id="forum_id" value="@if($forum){{$forum->id}}@endif"/>

                <div class="gg-list">
                    <label class="tit">用户昵称：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="昵称   " name="nick_name" id="nick_name" value="{{--@if($forumDiscuss){{$forumDiscuss->content}}@endif--}}" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>



                <div class="gg-list" data-id="ggwz">
                    <label class="tit">展示图</label>
                    <div class="demo" style="display: inline-block; padding: 0; margin: 0; *display: inline; *zoom:1;">
                        <input type = "hidden" name = "pic_img" id = "pic_img2" value = "" height="70px" >
                        <div id="showimg">
                        </div>
                        <div class="btn" style="background: #00A2D4">
                            <span id="inputImage">添加用户头像图片</span>
                            <input id="img_id" type="hidden" name="img_id" value="{{--@if($forumDiscuss){{$forumDiscuss->photo_id}}@endif--}}">
                        </div>
                        <div class="progress">
                            <span class="bar"></span><span class="percent">0%</span >
                        </div>
                        <p class="text" id="uploadthumb">{{--@if($forumDiscuss)--}}<img id="img_show" style="width: 100px;padding-top: 3px;" src=""{{--{{$forumDiscuss->photo__url}}" /> @else--}}上传用户头像（图片格式为jpg或png）{{--@endif--}}</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">评论内容：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="评论内容" name="discuss" id="discuss" value="{{--@if($forumDiscuss){{$forumDiscuss->content}}@endif--}}" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>
            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn_send">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>

        $(function() {



            $('#btn_send').click(function () {
                var nick_name       = $('#nick_name').val();
                var forum_id          = $('#forum_id').val();
                var forum_discuss_id =$('#forum_discuss_id').val();
                var  discuss     =$('#discuss').val();
                var photo_id      = $("#img_id").val();


                $.ajax({
                    url:"{{route('Api.Admin.Forum.setForumDiscuss')}}",
                    type:'post',
                    dataType:'json',
                    data:{
                        forum_id:forum_id,
                        content:discuss,
                        nick_name:nick_name,
                        forum_discuss_id:forum_discuss_id,
                        photo_id:photo_id,

                    },
                    success:function (obj) {
                        if(obj.level == 'success'){
                            noty({text:obj.message,type:obj.level,timeout:600,
                                callback:{
                                    afterClose:function(){
                                        window.location.href="{{route('Admin.Home.forumDiscussList')}}";
                                    }
                                }
                            });
                        }else {
                            noty({text:obj.message,type:obj.level,timeout:600});
                        }
                    },
                    error:function (obj) {
                        console.log(obj);
                    }
                });
            });

            //缩略图上传代码
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'inputImage',
                url: '{{route("Api.Upload.Image")}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {
                },

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {

                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }
                        if(responseObj.level == "success"){
                            $('#img_id').val(responseObj.data.id);
                            var imgURL = responseObj.data.img_url + "?" + Math.random();
                            $('#uploadthumb').html('<img src="'+imgURL+'" style="width: 100px;padding-top: 3px;" />');
                        }else{
                            noty({type:responseObj.level,text:responseObj.message,timeout:800});
                            $('#uploadthumb').html('<span style="color: red">上传失败，请重新上传！</span>');
                        }

                    }
                }
            });
            uploader.init();
        });
    </script>
@endsection